﻿namespace SenenFernandez.UniversalExtensions
{
    using System;
    using System.Collections.Generic;
    using System.Linq.Expressions;
    using System.Reflection;

    public static class Linq
    {
        public static bool AreDifferent<T>(this T value, T newValue)
        {
            return !EqualityComparer<T>.Default.Equals(value, newValue);
        }

        public static PropertyInfo GetProperty(this Type type, string propertyName)
        {
            return type.GetTypeInfo().GetDeclaredProperty(propertyName);
        }

        public static string GetPropertyName<T>(this Expression<Func<T>> propertyExpression)
        {
            string result = default(string);
            if (propertyExpression != null)
            {
                var memberExpression = propertyExpression.Body as MemberExpression;
                result = memberExpression.Member.Name;
            }
            return result;
        }
    }
}